<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Comment extends API_Controller {


	public function __construct() {
    	parent::__construct();
	}

	public function index(){

		$id = $this->input->post('id');

		$this->load->model('comment');
		$comment_list = $this->comment->get_comment_list($id);

		$data = array();
		if(!empty($comment_list)){

			$this->load->model('accept');
			foreach($comment_list as $comment){

				$is_accept = $this->accept->is_accept($comment['id']);

				$tmp = array();
				$tmp = array(
					'user_id' => $comment['user_id'],
					'user_pic' => $comment['user_pic'],
					'nick' => $comment['nick'],
					'comment_time' => $comment['comment_time'],
					'content' => $comment['comment'],
					'is_accept' => $is_accept
				);

				$data[] = $tmp;
			}
		}
		$this->to_api_message(1, '获取列表数据成功', $data, count($data));
	}

	public function do_comment(){

		$usre_id = 1;
		$id = $this->input->post('id');
		$content = $this->input->post('content');


		$this->load->model('comment');
		$insertData = array();
		$insertData = array(
			'list_id' => $id,
			'user_id' => $user_id,
			'comment' => $content,
			'comment_time' => date('Y-m-d H:i:s') 
		);
		$insert = $this->comment->insert($insertData);

		if($insert){
			$this->to_api_message(1, '评论成功');
		}else{
			$this->to_api_message(0, '评论失败');
		}
	}

	public function accept(){

		$usre_id = 1;
		$id = $this->input->post('comment_id');


		$this->load->model('accept');
		$insertData = array();
		$insertData = array(
			'list_id' => $id,
			'user_id' => $user_id,
			'accept_time' => date('Y-m-d H:i:s') 
		);
		$insert = $this->accept->insert($insertData);

		if($insert){
			$this->to_api_message(1, '采纳成功');
		}else{
			$this->to_api_message(0, '采纳失败');
		}
	}


}

/* End of file home.php */
/* Location: ./application/controllers/home.php */